package main

func isHappy(n int) bool {
	m := make(map[int]struct{})
	for {
		m[n] = struct{}{}
		n2 := 0
		for n > 0 {
			v := n % 10
			n /= 10
			n2 += v * v
		}
		if n2 == 1 {
			return true
		}
		if _, ok := m[n2]; ok {
			return false
		}
		n = n2
	}
}

func main() {
	println(isHappy(2))
}